'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.defaultBgImageValue = exports.defaultBgImageOrGradient = exports.linearGradientToDeg = exports.removeEditClassName = exports.alphaBg = exports.styleInUse = exports.getBgImageType = exports.getBgImageUrl = exports.mobileTitle = exports.colorLookup = exports.colorExp = undefined;

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

exports.toArrayChildren = toArrayChildren;
exports.isColor = isColor;
exports.getRandomKey = getRandomKey;
exports.firstUpperCase = firstUpperCase;
exports.removeMultiEmpty = removeMultiEmpty;
exports.getBorderDataToStyle = getBorderDataToStyle;
exports.getOption = getOption;
exports.getOptionArray = getOptionArray;
exports.getRadioButton = getRadioButton;
exports.getComputedStyle = getComputedStyle;
exports.convertData = convertData;
exports.convertDefaultData = convertDefaultData;
exports.getBgDefaultData = getBgDefaultData;
exports.convertBorderData = convertBorderData;
exports.convertShadowData = convertShadowData;
exports.toCss = toCss;
exports.getDomCssRule = getDomCssRule;
exports.getClassNameCssRule = getClassNameCssRule;
exports.getParentClassName = getParentClassName;
exports.currentScrollTop = currentScrollTop;
exports.getParentNode = getParentNode;
exports.getCssStr = getCssStr;
exports.unitToPercent = unitToPercent;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _select = require('antd/lib/select');

var _select2 = _interopRequireDefault(_select);

var _radio = require('antd/lib/radio');

var _radio2 = _interopRequireDefault(_radio);

var _specificity = require('specificity');

var _specificity2 = _interopRequireDefault(_specificity);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

/* eslint-disable no-useless-escape */
var Option = _select2['default'].Option;

var RadioButton = _radio2['default'].Button;

var colorExp = exports.colorExp = /^rgba?\(((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?)\)$|(#[\d\w]+|\w+\((?:\d+%?(?:,\s)*){3}(?:\d*\.?\d+)?\))|^hsla?\(((\d+),\s*([\d.]+)%,\s*([\d.]+)%(?:,\s*(\d+(?:\.\d+)?))?)\)$/ig; // eslint-disable-line max-len

var colorLookup = exports.colorLookup = {
  aqua: 'rgb(0, 255, 255)',
  lime: 'rgb(0, 255, 0)',
  silver: 'rgb(192, 192, 192)',
  black: 'rgb(0, 0, 0)',
  maroon: 'rgb(128, 0, 0)',
  teal: 'rgb(0, 128, 128)',
  blue: 'rgb(0, 0, 255)',
  navy: 'rgb(0, 0, 128)',
  white: 'rgb(255, 255, 255)',
  fuchsia: 'rgb(255, 0, 255)',
  olive: 'rgb(128, 128, 0)',
  yellow: 'rgb(255, 255, 0)',
  orange: 'rgb(255, 165, 0)',
  gray: 'rgb(128, 128, 128)',
  purple: 'rgb(128, 0, 128)',
  green: 'rgb(0, 128, 0)',
  red: 'rgb(255, 0, 0)',
  pink: 'rgb(255, 192, 203)',
  cyan: 'rgb(0, 255, 255)',
  transparent: 'rgba(255, 255, 255, 0)'
};

var classInherited = ['azimuth', 'border-collapse', 'border-spacing', 'caption-side', 'color', 'cursor', 'direction', 'elevation', 'empty-cells', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'font', 'letter-spacing', 'line-height', 'list-style-image', 'list-style-position', 'list-style-type', 'list-style', 'orphans', 'pitch-range', 'pitch', 'quotes', 'richness', 'speak-header', 'speak-numeral', 'speak-punctuation', 'speak', 'speech-rate', 'stress', 'text-align', 'text-indent', 'text-transform', 'text-decoration', 'visibility', 'voice-family', 'volume', 'white-space', 'widows', 'word-spacing'];

var mobileTitle = exports.mobileTitle = '@media screen and (max-width: 767px) {';

var getBgImageUrl = exports.getBgImageUrl = function getBgImageUrl(image) {
  return image.replace(/url\((('|"|&quot;)?)([^\s]+)\2\)/ig, '$3');
};

var getBgImageType = exports.getBgImageType = function getBgImageType(url) {
  var type = url && url.match(/(repeating-)?linear-gradient\(/i) ? 'linear' : 'img';
  type = url && url.match(/(repeating-)?radial-gradient\(/i) ? 'radial' : type;
  return type;
};

// 当跟默认值相同时，用于清除样式;
var styleInUse = exports.styleInUse = {
  'background-attachment': 1,
  'background-color': 1,
  'background-image': 1,
  'background-repeat': 1,
  'background-position': 1,
  'background-size': 1,
  'background-blend-mode': 1,
  'border-color': 1,
  'border-radius': 1,
  'border-style': 1,
  'border-width': 1,
  'text-align': 1,
  'text-decoration': 1,
  'letter-spacing': 1,
  'line-height': 1,
  color: 1,
  'font-size': 1,
  'font-family': 1,
  'font-weight': 1,
  bottom: 1,
  left: 1,
  top: 1,
  right: 1,
  position: 1,
  overflow: 1,
  width: 1,
  height: 1,
  'max-height': 1,
  'max-width': 1,
  'min-width': 1,
  'min-height': 1,
  margin: 1,
  padding: 1,
  'box-shadow': 1,
  'text-shadow': 1,
  cursor: 1,
  transition: 1,
  display: 1,
  'align-items': 1,
  'justify-content': 1,
  'z-index': 1,
  float: 1,
  clear: 1,
  opacity: 1
};
var alphaBg = exports.alphaBg = '' + '9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0p' + 'gAAAABJRU5ErkJggg==';

function toCssLowerCase(d) {
  return d.replace(/[A-Z]/, function ($1) {
    return '-' + $1.toLocaleLowerCase();
  });
}

function toStyleUpperCase(d) {
  return d.replace(/-(.?)/g, function ($1) {
    return $1.replace('-', '').toLocaleUpperCase();
  });
}

function toArrayChildren(children) {
  var ret = [];
  _react2['default'].Children.forEach(children, function (c) {
    ret.push(c);
  });
  return ret;
}

function isColor(v) {
  return v.match(colorExp) || colorLookup[v];
}

function getRandomKey() {
  return (Date.now() + Math.random()).toString(36).replace('.', '');
}

function firstUpperCase(str) {
  return '' + str.charAt(0).toLocaleUpperCase() + str.slice(1);
}

function removeMultiEmpty(str) {
  return str.replace(/\s+/g, ' ');
}

var removeEditClassName = exports.removeEditClassName = function removeEditClassName(t, reClass) {
  return t.split(' ').filter(function (name) {
    return name.indexOf(reClass) === -1;
  }).join(' ');
};

function getBorderDataToStyle(name, d) {
  var key = firstUpperCase(name);
  if (d && typeof d === 'object') {
    var _ref2;

    if (key === 'radius') {
      var _ref;

      return _ref = {}, (0, _defineProperty3['default'])(_ref, 'borderTopLeft' + key, d.topLeft), (0, _defineProperty3['default'])(_ref, 'borderTopRight' + key, d.topRight), (0, _defineProperty3['default'])(_ref, 'borderBottomRight' + key, d.bottomRight), (0, _defineProperty3['default'])(_ref, 'borderBottomLeft' + key, d.bottomLeft), _ref;
    }
    return _ref2 = {}, (0, _defineProperty3['default'])(_ref2, 'borderTop' + key, d.top), (0, _defineProperty3['default'])(_ref2, 'borderRight' + key, d.right), (0, _defineProperty3['default'])(_ref2, 'borderBottom' + key, d.bottom), (0, _defineProperty3['default'])(_ref2, 'borderLeft' + key, d.left), _ref2;
  }
  return (0, _defineProperty3['default'])({}, 'border' + key, d);
}

function getOption(value, noKey) {
  return Object.keys(value).map(function (key) {
    return _react2['default'].createElement(
      Option,
      { key: key, value: key },
      noKey ? value[key] : value[key] + ' - ' + key
    );
  });
}

function getOptionArray(array) {
  return array.map(function (key) {
    return _react2['default'].createElement(
      Option,
      { key: key, value: key },
      key
    );
  });
}

function getRadioButton(array) {
  return array.map(function (key) {
    return _react2['default'].createElement(
      RadioButton,
      { value: key, key: key, className: 'ant-radio-button-auto-width' },
      key
    );
  });
}

function getComputedStyle(target) {
  return document.defaultView ? document.defaultView.getComputedStyle(target) : {};
}

function convertData(d, b) {
  var c = b ? !d && typeof d !== 'number' || d.indexOf('none') >= 0 || d.indexOf('normal') >= 0 : !d || d === '0px' || d.indexOf('normal') >= 0;
  if (c) {
    return null;
  }
  return d;
}

function convertDefaultData(d) {
  if (!d || d === 'repeat' || d === '0% 0%' || d === 'auto' || d === 'scroll' || d === 'start' || d === 'visible') {
    return null;
  }
  return d;
}

var linearGradientToDeg = exports.linearGradientToDeg = {
  'to top': 0,
  'to right': 90,
  'to bottom': 180,
  'to left': 270,
  'to top right': 45,
  'to bottom right': 135,
  'to bottom left': 225,
  'to top left': 315,
  'to right top': 45,
  'to right bottom': 135,
  'to left top': 315,
  'to left bottom': 225
};

var defaultBgImageOrGradient = exports.defaultBgImageOrGradient = {
  img: 'url("https://zos.alipayobjects.com/rmsportal/gGlUMYGEIvjDOOw.jpg")',
  linear: 'linear-gradient(to bottom, black 0%, white 100%)',
  radial: 'radial-gradient(circle at center, black 0%, white 100%)'
};

var defaultBgImageValue = exports.defaultBgImageValue = {
  image: defaultBgImageOrGradient.img,
  attachment: '',
  blendMode: '',
  position: '',
  repeat: '',
  size: '',
  clip: ''

  // attachment: 'scroll',
  // blendMode: 'normal',
  // position: '0% 0%',
  // repeat: 'repeat',
  // size: 'auto',
  // clip: 'padding-box',
};

function getBgDefaultData(style) {
  var data = {};
  Object.keys(defaultBgImageValue).forEach(function ($key) {
    var key = 'background-' + toCssLowerCase($key);
    var item = style[key];
    if (item && style.backgroundImage && style.backgroundImage !== 'none') {
      data[$key] = $key === 'image' ? item.replace(/\),(\s?)(?=(url|linear|radial|repeating))/, ')&EditorListUrlPlaceholder&').split('&EditorListUrlPlaceholder&') : item.split(',');
    } else {
      data[$key] = [];
    }
  });
  var length = Object.keys(data).map(function (item) {
    return data[item].length;
  }).sort(function (a, b) {
    return a - b > 0;
  })[0];
  new Array(length).fill(1).forEach(function (_, i) {
    Object.keys(data).forEach(function (key) {
      var item = data[key][i];
      if (!item) {
        item = data[key][0] || defaultBgImageValue[key];
        data[key][i] = item;
      }
      if (item.trim() === 'initial') {
        data[key][i] = defaultBgImageValue[key];
      }
    });
  });
  return data;
}

function convertBorderData(d, width, isRadius) {
  if (!d) {
    return '';
  }
  if (typeof d === 'object') {
    return d;
  }
  var dataIsColor = isColor(d);
  var dArray = dataIsColor || d.split(' ');
  if (dArray.length > 1) {
    var top = convertData(dArray[0]);
    var right = convertData(dArray[1]);
    var bottom = convertData(dArray[2] || dArray[0]);
    var left = convertData(dArray[3] || dArray[1]);
    if (width) {
      var wArray = width.split(' ');
      wArray[1] = wArray[1] || wArray[0];
      wArray[2] = wArray[2] || wArray[0];
      wArray[3] = wArray[3] || wArray[1];
      top = parseFloat(wArray[0]) && top || null;
      right = parseFloat(wArray[1]) && right || null;
      bottom = parseFloat(wArray[2]) && bottom || null;
      left = parseFloat(wArray[3]) && left || null;
    }
    if (isRadius) {
      return { 'top-left': top, 'top-right': right, 'bottom-right': bottom, 'bottom-left': left };
    }
    return { top: top, right: right, bottom: bottom, left: left };
  }
  return convertData(d);
}

function convertShadowData(d) {
  if (!convertData(d)) {
    return {};
  }
  var dataArray = d.replace(/\,\s+/g, ',').split(/\s+/);
  var color = void 0;
  var noColor = dataArray.map(function (c) {
    if (isColor(c) || colorLookup[c]) {
      color = c;
      return null;
    }
    return c;
  }).filter(function (item) {
    return item;
  });
  var keys = ['x', 'y', 'blur', 'spread', 'inset'];
  var value = { color: color };
  noColor.forEach(function (data, i) {
    value[keys[i]] = i === 3 ? convertData(data) : data;
  });
  return value;
}

function fontToCss(d, current) {
  return Object.keys(d).map(function (key) {
    var data = d[key];
    if (!data || data === current[key]) {
      return null;
    } else if (key === 'letterSpacing' || key === 'lineHeight' || key === 'color') {
      return toCssLowerCase(key) + ': ' + data + ';';
    } else if (key === 'align' || key === 'decoration') {
      return 'text-' + key + ': ' + data + ';';
    }
    return 'font-' + key + ': ' + data + ';';
  }).filter(function (item) {
    return item;
  }).join('\n');
}

function cssUnique(array) {
  if (array[1] === array[3]) {
    array.splice(3, 1);
    if (array[0] === array[2]) {
      array.splice(2, 1);
    }
  }
  return array;
}

function borderToCss(d, current) {
  if (!d.style && !d.radius) {
    return null;
  }
  return Object.keys(d).map(function (key) {
    var data = d[key];
    if (!data || current[key] === data) {
      return null;
    }
    if (typeof data === 'string') {
      return 'border-' + key + ': ' + data + ';';
    }
    return Object.keys(data).map(function (cKey) {
      var cData = data[cKey];
      var currentData = current[key] && current[key][cKey];
      if (!cData || cData === 'none' || currentData === cData) {
        return null;
      }
      return 'border-' + cKey + '-' + key + ': ' + cData + ';';
    }).filter(function (item) {
      return item;
    }).join('\n');
  }).filter(function (item) {
    return item;
  }).join('\n');
}

function marginToCss(d, current) {
  // 合并 margin padding, 用一个样式。。toStyleString 样式太多;
  function getMargin(obj) {
    return cssUnique(Object.keys(obj).map(function (key) {
      return key === 'center' ? null : obj[key] || 0;
    })).join(' ');
  }

  return Object.keys(d).map(function (key) {
    var style = key + ': ';
    var data = d[key];
    if (!data || current[key] === data) {
      return null;
    } else if (typeof data === 'string') {
      return '' + style + data + ';';
    }
    var str = getMargin(data);
    var currentStr = current[key] && getMargin(current[key]);
    if (str === currentStr) {
      return null;
    }
    return '' + style + str + ';';
  }).filter(function (item) {
    return item;
  }).join('\n');
}

function shadowToCss(d, current) {
  return Object.keys(d).map(function (key) {
    var data = d[key];
    if (typeof data === 'string') {
      return removeMultiEmpty(toCssLowerCase(key) + ': ' + data + ';').trim();
    }
    var cData = current[key];
    if (!data || !Object.keys(data).length) {
      return null;
    }
    if (data.x === cData.x && data.y === cData.y && data.blur === cData.blur && data.spread === cData.spread && data.color === cData.color && data.inset === cData.inset) {
      return null;
    }
    return removeMultiEmpty(toCssLowerCase(key) + ': ' + (data.x || 0) + ' ' + (data.y || 0) + ' ' + (data.blur || 0) + ' ' + (data.spread || '') + ' ' + data.color + ' ' + (data.inset || '') + ';').trim();
  }).filter(function (item) {
    return item;
  }).join('\n');
}

function backgroundToCss(d, current) {
  return Object.keys(d).map(function (key) {
    var data = d[key];
    if (!data || current[key] === data) {
      return null;
    }
    if (key === 'image') {
      var t = Object.keys(data).map(function ($key) {
        var item = data[$key];
        var currentItem = current[key][$key];
        if (!item || item.join() === currentItem.join()) {
          return null;
        }
        if (item === 'none') {
          return 'background-' + toCssLowerCase($key) + ': none;';
        }
        return 'background-' + toCssLowerCase($key) + ': ' + item.join(',') + ';';
      }).filter(function (c) {
        return c;
      });
      return t.join('\n');
    }
    return 'background-' + key + ': ' + data + ';';
  }).filter(function (item) {
    return item;
  }).join('\n');
}

function defaultToCss(d, current) {
  return Object.keys(d).map(function (key) {
    var data = d[key];
    if (!data && data !== 0 || current[key] === data) {
      return null;
    }
    return toCssLowerCase(key) + ': ' + data + ';';
  }).filter(function (item) {
    return item;
  }).join('\n');
}

function toCss(newData, currentData) {
  var css = '';
  Object.keys(newData).forEach(function (key) {
    var addCss = void 0;
    switch (key) {
      case 'state':
        addCss = newData[key] && newData[key].cursor !== currentData[key].cursor ? 'cursor: ' + newData[key].cursor + ';' : '';
        break;
      case 'layout':
        addCss = defaultToCss(newData[key], currentData[key]);

        break;
      case 'font':
        addCss = fontToCss(newData[key], currentData[key]);
        break;
      case 'interface':
        addCss = defaultToCss(newData[key], currentData[key]);
        break;
      case 'background':
        addCss = backgroundToCss(newData[key], currentData[key]);
        break;
      case 'border':
        addCss = borderToCss(newData[key], currentData[key]);
        break;
      case 'margin':
        addCss = marginToCss(newData[key], currentData[key]);
        break;
      case 'shadow':
        addCss = shadowToCss(newData[key], currentData[key]);
        break;
      case 'transition':
        addCss = newData[key] && currentData[key] !== newData[key] && newData[key] !== 'all 0s ease 0s' ? 'transition: ' + newData[key] : '';
        break;
      default:
        break;
    }
    if (addCss && addCss !== ';') {
      css = css && addCss ? css + '\n' + addCss : addCss;
    }
  });
  return css;
}

// chrome state;
var styleState = ['hover', 'focus', 'active', 'visited', 'focus-within'];

function contrastParent(node, d) {
  if (node === d) {
    return true;
  } else if (!node) {
    return false;
  }
  return contrastParent(node.parentNode, d);
}

function cssRulesForEach(item, i, newStyleState, styleObj, dom, ownerDocument, isMobile, state, className, onlyMobile, media, cj) {
  var rep = new RegExp(':' + state + '$');
  // state === 'active' ? `(\:${state}|\:hover)$` :
  // `\\.${className}(:(hover|focus|active))?\s*(?=(,|$))`
  var repClassName = className || dom.className.split(' ').join('|');
  var classRep = new RegExp('\\.' + (state ? '(' + (className || repClassName) + '):' + state : '(' + repClassName + ')') + '?s*(?=(,|$))');
  item.forEach(function (cssStyle, j) {
    if (cssStyle.conditionText && cssStyle.media && cssStyle.cssRules && isMobile) {
      return cssRulesForEach(Array.prototype.slice.call(cssStyle.cssRules || []), i, newStyleState, styleObj, dom, ownerDocument, isMobile, state, className, onlyMobile, 'moblie', j);
    }
    if (onlyMobile && !media) {
      return null;
    }
    var select = cssStyle.selectorText;
    // 删除内建样式, https://github.com/ant-design/ant-design-landing/issues/42;
    if (!select || !select.split(',').filter(function (c) {
      return c;
    }).some(function (str) {
      return !str.trim().match(/^(\[[a-z]+=".*"?\])|(\:\:\-webkit\-)/g);
    })) {
      return null;
    }
    // 去除所有不是状态的
    var childrenArray = [];
    var isParent = void 0;
    // className 为 null
    if (!className) {
      childrenArray = Array.prototype.slice.call(ownerDocument.querySelectorAll(select.trim().replace(state ? rep : '', '')));
      isParent = childrenArray.some(function (d) {
        return contrastParent(dom, d);
      });
    }
    if (select.match(classRep) || isParent) {
      var cssText = cssStyle.style.cssText;
      var currentDomStr = select.split(',').filter(function (str) {
        if (className && !str.match(classRep)) {
          return false;
        }
        var surplus = state ? !str.match(rep) : newStyleState.map(function (key) {
          var newKey = ':' + key;
          return str.indexOf(newKey) >= 0;
        }).some(function (c) {
          return c;
        });
        if (surplus) {
          return false;
        }
        if (className) {
          return str.match(classRep) && str;
        }
        // 判断是不是状态样式
        childrenArray.forEach(function (d) {
          var isDom = contrastParent(dom, d);
          if (isDom && d !== dom) {
            // 获取继承的样式
            cssText = '' + cssText.split(';').filter(function (css) {
              var cssName = css.split(':')[0].trim();
              return classInherited.indexOf(cssName) >= 0;
            }).join(';');
            cssText = cssText ? cssText + ';' : '';
          }
        });
        // some attached value: Unexpected assignment within ConditionalExpression;
        return isParent ? str : null;
      })[0];
      if (currentDomStr) {
        var newSelectName = currentDomStr + '~' + i + (cj ? '~' + cj : '') + '~' + j + (media ? '~' + media : '');
        styleObj[newSelectName] = cssText;
      }
    }
    return null;
  });
}

function getCssPropertyForRuleToCss(_ref4) {
  var dom = _ref4.dom,
      ownerDocument = _ref4.ownerDocument,
      isMobile = _ref4.isMobile,
      state = _ref4.state,
      className = _ref4.className,
      onlyMobile = _ref4.onlyMobile;

  var style = '';
  var styleObj = {};
  var newStyleState = styleState.map(function (key) {
    return (state === 'active' ? key !== state || key !== 'hover' : key !== state) && key;
  }).filter(function (c) {
    return c;
  });
  Array.prototype.slice.call(ownerDocument.styleSheets || []).forEach(function (item, i) {
    if (item.href) {
      try {
        var host = item.href.match(/(:\/\/)(.+?)\//i)[2];
        if (host !== ownerDocument.location['host']) {
          return;
        }
      } catch (e) {}
    }
    try {
      if (!item.cssRules) {
        return;
      }
    } catch (e) {
      if (e.name !== 'SecurityError') {
        throw e;
      }
      return;
    }
    cssRulesForEach(Array.prototype.slice.call(item.cssRules), i, newStyleState, styleObj, dom, ownerDocument, isMobile, state, className, onlyMobile);
  });
  Object.keys(styleObj).sort(function (a, b) {
    var aArray = a.split('~');
    var bArray = b.split('~');
    return _specificity2['default'].compare(aArray[0], bArray[0]) || parseFloat(aArray[1]) - parseFloat(bArray[1]) || parseFloat(aArray[2]) - parseFloat(bArray[2]) || aArray.length - bArray.length || parseFloat(aArray[3]) - parseFloat(bArray[3]);
  }).forEach(function (key) {
    style += styleObj[key];
  });
  return style;
}

var removeEmptyStyle = function removeEmptyStyle(s) {
  var style = {};
  Array(s.length).fill(1).forEach(function (k, i) {
    var key = s[i];
    var value = s[key];
    if (value && value !== 'initial' && value !== 'normal') {
      if (key.indexOf('background-repeat') >= 0) {
        style['background-repeat'] = s['background-repeat'];
        style.backgroundRepeat = s.backgroundRepeat;
      }
      if (key.indexOf('background-position') >= 0) {
        style['background-position'] = s['background-position'];
        style.backgroundPosition = s.backgroundPosition;
      }
      style[key] = s[key];
      style[toStyleUpperCase(key)] = s[key];
      if (key.indexOf('transition') >= 0) {
        style.transition = s.transition;
      }
    }
  });
  return style;
};

function getDomCssRule(_ref5) {
  var dom = _ref5.dom,
      isMobile = _ref5.isMobile,
      state = _ref5.state,
      onlyMobile = _ref5.onlyMobile;

  var ownerDocument = dom.ownerDocument;
  var div = ownerDocument.createElement(dom.tagName.toLocaleLowerCase());
  dom.parentNode.appendChild(div);
  // 有 vh 的情况下，computedStyle 会把 vh 转化成 px，用遍历样式找出全部样式
  var style = '' + getCssPropertyForRuleToCss({
    dom: dom, ownerDocument: ownerDocument,
    isMobile: isMobile, state: state, onlyMobile: onlyMobile
  });
  // 给 style 去重;
  div.style = '' + style + dom.style.cssText;
  if (!div.style.display) {
    div.style.display = getComputedStyle(div).display;
  }
  // 获取当前 div 带 vh 的样式；
  var styleObject = removeEmptyStyle(div.style);
  div.remove();
  return styleObject;
}

function getClassNameCssRule(_ref6) {
  var dom = _ref6.dom,
      className = _ref6.className,
      isMobile = _ref6.isMobile,
      onlyMobile = _ref6.onlyMobile,
      state = _ref6.state,
      getObject = _ref6.getObject;

  var ownerDocument = dom.ownerDocument;
  var div = ownerDocument.createElement('div');
  var style = getCssPropertyForRuleToCss({
    dom: dom, ownerDocument: ownerDocument,
    isMobile: isMobile, state: state, className: className, onlyMobile: onlyMobile
  });
  div.style = style;
  var styleData = getObject ? removeEmptyStyle(div.style) : div.style.cssText;
  div.remove();
  return styleData;
}

function getParentClassName(dom, rootSelector) {
  var useTagName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  var length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 50;

  var className = '';
  var i = 0;
  var rootDom = dom.ownerDocument.querySelectorAll(rootSelector)[0];

  function getParentClass(d) {
    // 当切换很快的时候 会出现d = null
    if (!d || !d.className) {
      return;
    }
    var p = d.className;
    if (d === rootDom) {
      return;
    }
    var tagName = useTagName ? d.tagName.toLocaleLowerCase() : null;
    p = p ? '.' + p.split(/\s+/g)[0] : tagName;
    className = p ? (p + ' > ' + className).trim() : className;
    if (useTagName || !useTagName && d.className) {
      i += 1;
    }
    if (i >= length) {
      return;
    }
    if (d.parentNode.tagName.toLocaleLowerCase() !== 'html') {
      getParentClass(d.parentNode);
    }
  }

  if (rootDom !== dom) {
    getParentClass(dom.parentNode);
  }
  return rootSelector ? (rootSelector + ' ' + className).trim() : className;
}

function currentScrollTop() {
  return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
}

function getParentNode(node, className, toBool) {
  var parent = node.parentNode;
  var classNameArray = (parent.className || '').split(' ').some(function (name) {
    if (Array.isArray(className)) {
      return className.indexOf(name) >= 0;
    }
    return name === className;
  });
  if (classNameArray || parent.tagName.toLocaleLowerCase() === 'body') {
    var isBody = parent.tagName.toLocaleLowerCase() === 'body';
    return toBool ? !isBody : parent;
  }
  return getParentNode(parent, className, toBool);
}

function getCssStr(cssString, className) {
  var reStr = '.' + className + '[\\s\\n?]*\\{\\n?([^\\}]+?)\\n?\\}';
  var re = new RegExp(reStr, "gi");
  var css = cssString.match(re);
  var str = '';
  if (css) {
    css.forEach(function (string) {
      var reg = new RegExp(reStr, 'gm');
      str += string.replace(reg, '$1');
    });
  }
  return str;
}

function unitToPercent(dom, value, unit) {
  if (unit === '%') {
    return value;
  }
  var pix = parseFloat(value);
  var computedStyle = void 0;
  switch (unit) {
    case 'em':
      computedStyle = getComputedStyle(dom);
      pix *= parseFloat(computedStyle.fontSize);
      break;
    case 'rem':
      computedStyle = getComputedStyle(document.getElementsByTagName('html')[0]);
      pix *= parseFloat(computedStyle.fontSize);
      break;
    case 'vw':
      pix = pix * document.body.clientWidth / 100;
      break;
    case 'vh':
      pix = pix * document.body.clientHeight / 100;
      break;
    default:
      break;
  }
  var rect = dom.getBoundingClientRect();
  pix = pix / rect.width * 100;
  return pix + '%';
}